﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace LogFileConnector
{
    class ErrorHandler
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public static void processInfoOutput(string message)
        {
            Console.WriteLine(message);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public static void writeLogError(string message)
        {
            if (Configuration.showLogFileErrors)
            {
                writeLog("Invalid Logfile: "+message);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public static void writeLog(string message) 
        {
            if (Configuration.writeLog)
            {
                StreamWriter writer= new StreamWriter("log.txt", true);
                try
                {
                    if (Configuration.logOutputDestination == "screen")
                    {
                        Console.WriteLine(message);
                    }
                    else if (Configuration.logOutputDestination == "file")
                    {
                        writer.WriteLine(message);
                        writer.Close();
                    }
                }
                catch (Exception error)
                {
                    Console.WriteLine("Konnte die Log nicht schreiben " + error.Message);
                }
                finally
                {
                    writer.Close();
                }
            }
        }
    }
}
